using net_work.Config;
using net_work.Data.DTO.Appr;
using net_work.Data.Entity.Appr;
using net_work.IRepository.Appr;

namespace net_work.Repository.Appr;

public class ApprovalInstanceHistoryRepository(ApplicationDbContext dbContext)
    : Repository<ApprovalInstanceHistory>(dbContext), IApprovalInstanceHistoryRepository
{
    public async Task<long> InsertAsync(ApprovalInstanceHistoryAddRequestBackend approvalInstanceAddRequest)
    {
        var approvalInstanceHistory = new ApprovalInstanceHistory
        {
            Remark = approvalInstanceAddRequest.Remark,
            Result = approvalInstanceAddRequest.Result,
            Content = approvalInstanceAddRequest.Content,
            InstanceId = approvalInstanceAddRequest.InstanceId,
            FlowNodeId = approvalInstanceAddRequest.FlowNodeId,
        };

        await dbContext.ApprovalInstanceHistories.AddAsync(approvalInstanceHistory);
        await dbContext.SaveChangesAsync();
        return approvalInstanceHistory.Id;
    }
}